import { h, render } from "."
import { camelize, capitalize, isString } from "../utils"
let components
export function createApp(rootComponent) {
    // 注册的子组件组件
    components = rootComponent.components || {}
    const app = {
        mount(rootContainer) {
            console.log('999');
            // 如果传递过来的是id选择器
            if (isString(rootContainer)) {
                rootContainer = document.querySelector(rootContainer)
            }
            // 没有template选项也没有render函数
            if (!rootComponent.render && !rootComponent.template) {
                rootComponent.template = rootContainer.innerHTML
            }
            // 要清空，否则会渲染两遍
            rootContainer.innerHTML = ''
            render(h(rootComponent), rootContainer)
        }
    }
    return app
}

export function resolveComponent(name) {
    // name是组件名称
    return (components && components[name] || camelize(name) || capitalize(camelize(name)))
}
// 三种组件写法
// tree-item treeItem TreeItem